using System;
using PowerSearch.AppServices.Parser;
using System.Collections.Generic;
using PowerSearch.Core;

namespace PowerSearch.AppServices
{
	public class SearchService : ISearchService
	{
		private FeedParserManager _parserManager;

		public SearchService()
		{
			_parserManager = new FeedParserManager();
		}

		public IList<Feed> GetSearchResults(string keyword)
		{
			var providers = new string[] { "BBC", 
				"CNN", 
				"Ebay", 
				"ESPN", 
				"Flickr", 
				"HuffingtonPost", 
				"PeopleMagazine", 
				"TMZ", 
				"Twitter", 
				"Wikipedia", 
				"Yahoo", 
				"Youtube"};

			return GetSearchResults(keyword, providers);
		}

		public IList<Feed> GetSearchResults(string keyword, string[] providers)
		{
			var results = new List<Feed>();

			foreach (string provider in providers)
			{
				var parser = _parserManager.GetParser(provider);
				if (parser != null){
					var feeds = parser.GetFeeds(keyword);
					if (feeds != null && feeds.Count > 0)
						results.AddRange(feeds);
				}					
			}

			return results;
		}
	}
}

